#######################################
# REPLICATION: OBSERVATIONAL STUDY ####
# Handi Li, June 2025    
#######################################

## Load Packages ####

packages <- c("readr","tidyverse","fixest")

for (pkg in packages) {
  if (!require(pkg, character.only = TRUE)) {
    install.packages(pkg)
    library(pkg, character.only = TRUE)
  }
}

## Load Data ####

d.obs_all <- read_csv("/data_obs.csv")

## Result for Table B.1 (main result) ####

m.protest <- feols(protest_pc ~ l.transparency | province + year, data = d.obs_all, cluster = ~province + year)
m.protest.violent <- feols(protest_violent_pc ~ l.transparency | province + year, data = d.obs_all, cluster = ~province + year)
m.protest.home <- feols(protest_home_pc ~ l.transparency | province + year, data = d.obs_all, cluster = ~province + year)
m.protest.land <- feols(protest_land_pc ~ l.transparency | province + year, data = d.obs_all, cluster = ~province + year)

m.protest.ld <- feols(protest_pc ~ l.protest_total + l.transparency + gdp + built_area + requisition + l.disciplined +
                                unemployment_rate + illiterate_rate + internet_coverage | province + year, data = d.obs_all, cluster = ~province + year)
m.protest.violent.ld <- feols(protest_violent_pc ~ l.protest_violent_pc + l.transparency + gdp + built_area + requisition + l.disciplined +
                                        unemployment_rate + illiterate_rate + internet_coverage | province + year, data = d.obs_all, cluster = ~province + year)
m.protest.home.ld <- feols(protest_home_pc ~ l.protest_home_pc + l.transparency + gdp + built_area + requisition + l.disciplined +
                                     unemployment_rate + illiterate_rate + internet_coverage | province + year, data = d.obs_all, cluster = ~province + year)
m.protest.land.ld <- feols(protest_land_pc ~ l.protest_land_pc + l.transparency + gdp + built_area + requisition + l.disciplined +
                                     unemployment_rate + illiterate_rate + internet_coverage | province + year, data = d.obs_all, cluster = ~province + year)

m.protest.control <- feols(protest_pc ~  l.transparency + gdp + built_area + requisition + 
                                     unemployment_rate + illiterate_rate + internet_coverage | province + year, data = d.obs_all, cluster = ~province + year)
m.protest.violent.control <- feols(protest_violent_pc ~ l.transparency + gdp + built_area + requisition + 
                                             unemployment_rate + illiterate_rate + internet_coverage | province + year, data = d.obs_all, cluster = ~province + year)
m.protest.home.control <- feols(protest_home_pc ~ l.transparency + gdp + built_area + requisition + 
                                          unemployment_rate + illiterate_rate + internet_coverage | province + year, data = d.obs_all, cluster = ~province + year)
m.protest.land.control <- feols(protest_land_pc ~ l.transparency + gdp + built_area + requisition + 
                                          unemployment_rate + illiterate_rate + internet_coverage | province + year, data = d.obs_all, cluster = ~province + year)

m.protest.control2 <- feols(protest_pc ~  l.transparency + gdp + built_area + requisition + l.disciplined +
                                      unemployment_rate + illiterate_rate + internet_coverage | province + year, data = d.obs_all, cluster = ~province + year)
m.protest.violent.control2 <- feols(protest_violent_pc ~ l.transparency + gdp + built_area + requisition + l.disciplined +
                                              unemployment_rate + illiterate_rate + internet_coverage | province + year, data = d.obs_all, cluster = ~province + year)
m.protest.home.control2 <- feols(protest_home_pc ~ l.transparency + gdp + built_area + requisition + l.disciplined +
                                           unemployment_rate + illiterate_rate + internet_coverage | province + year, data = d.obs_all, cluster = ~province + year)
m.protest.land.control2 <- feols(protest_land_pc ~ l.transparency + gdp + built_area + requisition + l.disciplined +
                                           unemployment_rate + illiterate_rate + internet_coverage | province + year, data = d.obs_all, cluster = ~province + year)

## Result for Table F.3 (suggestive pattern) ####

m.adminlit.1 <- feols(nonogi_lit_pc~l.transparency | province, data = d.obs_all, cluster = ~province)

m.adminlit.2 <- feols(nonogi_lit_pc~l.transparency + gdp + built_area + requisition + 
                        unemployment_rate + illiterate_rate + internet_coverage | province, data = d.obs_all, cluster = ~province)

m.adminlit.3 <- feols(nonogi_lit_pc~l.transparency + gdp + built_area + requisition + l.disciplined +
                        unemployment_rate + illiterate_rate + internet_coverage | province, data = d.obs_all, cluster = ~province)

m.adminlit.4 <- feols(nonogi_lit_pc~l.nonogi_lit_pc + l.transparency + gdp + built_area + requisition + l.disciplined +
                        unemployment_rate + illiterate_rate + internet_coverage | province, data = d.obs_all, cluster = ~province)

m.adminrev.1 <- feols(nonogi_review_pc~l.transparency | province, data = d.obs_all, cluster = ~province)

m.adminrev.2 <- feols(nonogi_review_pc~l.transparency + gdp + built_area + requisition + 
                        unemployment_rate + illiterate_rate + internet_coverage | province, data = d.obs_all, cluster = ~province)

m.adminrev.3 <- feols(nonogi_review_pc~l.transparency + gdp + built_area + requisition + l.disciplined +
                        unemployment_rate + illiterate_rate + internet_coverage | province, data = d.obs_all, cluster = ~province)

m.adminrev.4 <- feols(nonogi_review_pc~l.nonogi_review_pc + l.transparency + gdp + built_area + requisition + l.disciplined +
                        unemployment_rate + illiterate_rate + internet_coverage | province, data = d.obs_all, cluster = ~province)
